import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import classNames from "classnames";
import React, { useLayoutEffect } from "react";
import styles from "./index.module.less";
import { useMount, useSetState } from "ahooks";
import countryList from "../../api/country";
import { login } from "../../api/user";
import { findAccount } from "../../api/wallet";
import utilsBase from "../../utils/basc";
import { useDispatch } from "react-redux";
import useRequest from "../../hooks/useRequest";
import { EVENT, KEYCONST } from "../../enums";
import kingsInstance from "../../instance";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
function Login() {
    var checkpass = function checkpass() {
        if (state.pass) {
            if (!utilsBase._checkPwd(state.pass)) {
                setState({
                    error: true,
                    errortxt: "Password error"
                });
            } else {
                setState({
                    error: false
                });
            }
        } else {
            setState({
                error: false
            });
        }
    };
    var backbtn = function backbtn() {
        setState({
            show: undefined,
            showqh: false
        });
        setTimeout(function() {
            setState({
                show: 0
            });
        }, 300);
    };
    var goforgetpass = function goforgetpass() {
        dispatch.app.PUSH({
            path: "/forgetpass",
            query: {
                show: state.show
            }
        });
    };
    var goregister = function goregister() {
        dispatch.app.PUSH({
            path: "/register"
        });
    };
    var go_login = function go_login() {
        // state.$router.push({
        //     path: `/invitecode`,
        // });
        // state.$loading({
        //     fullscreen:true
        // })
        // return
        if (state.show == 1) {
            setState({
                errortxt: "Select a login mode",
                error: true
            });
            return;
        }
        if (state.show == 2) {
            state.email = state.email.toString().replace(/\s/g, "");
            if (!utilsBase.checkEmail(state.email)) {
                setState({
                    errortxt: "Enter a valid Email!",
                    error: true
                });
                return;
            }
        }
        if (state.show == 3) {
            state.phone = state.phone.toString().replace(/\s/g, "");
            if (!state.phone) {
                setState({
                    errortxt: "Enter a valid phone number!",
                    error: true
                });
                return;
            }
        }
        state.pass = state.pass.toString().replace(/\s/g, "");
        if (!utilsBase._checkPwd(state.pass)) {
            setState({
                errortxt: "Password error",
                error: true
            });
            return;
        }
        var data = {
            password: state.pass,
            email: undefined,
            areaCode: undefined,
            loginName: undefined
        };
        if (state.show == 2) {
            data.loginName = state.email;
        } else {
            //data.areaCode = state.areaCoed;
            data.loginName = "".concat(state.areaCoed, "-").concat(state.phone);
        }
        services.login(data, true).then(function(res) {
            // localStorage.setItem("token", JSON.stringify(res.data));
            // state.gohome();
            if (res.code == 200) {
                localStorage.setItem(KEYCONST.token, JSON.stringify(res.data));
                localStorage.setItem(KEYCONST.userInfo, JSON.stringify(res.data.userDetail));
                dispatch.app.SET_USER_INFO(res.data.userDetail);
                services.findAccount({}, true).then(function(resa) {
                    localStorage.setItem(KEYCONST.wallet, JSON.stringify(resa.data));
                    kingsInstance.emit(EVENT.connect, _object_spread_props(_object_spread({}, res.data), {
                        wallet: resa.data
                    }));
                    dispatch.app.PUSH({
                        path: "/home"
                    });
                }).catch(function(err) {
                    console.log("err", err);
                });
            } else {
                setState({
                    error: true,
                    errortxt: res.msg
                });
            }
        }).catch(function(err) {
            console.log("err", err);
            setState({
                pass: ""
            });
        });
    };
    var _useSetState = _sliced_to_array(useSetState({
        show: 0,
        email: "",
        phone: "",
        showqh: false,
        areaCoed: "+86",
        countryList: countryList.countryList,
        load: true,
        pass: "",
        errortxt: "",
        error: false,
        isfirst: true,
        bgGif: ""
    }), 2), state = _useSetState[0], setState = _useSetState[1];
    var dispatch = useDispatch();
    var services = useRequest({
        login: login,
        findAccount: findAccount
    });
    useMount(function() {
        setTimeout(function() {
            setState({
                isfirst: false
            });
        }, 3000);
    });
    useLayoutEffect(function() {
        setState({
            bgGif: Math.random().toString()
        });
    }, []);
    return /*#__PURE__*/ _jsxs("div", {
        className: styles.content,
        children: [
            /*#__PURE__*/ _jsxs("div", {
                className: styles.loginbox,
                children: [
                    /*#__PURE__*/ _jsx("img", {
                        className: styles.loginbg,
                        src: require("../../assets/img/stp.gif") + "?" + state.bgGif,
                        alt: ""
                    }),
                    /*#__PURE__*/ _jsx("img", {
                        className: classNames(styles.loginbg1, state.isfirst ? styles.op : styles.op2),
                        src: require("../../assets/img/stp01.gif"),
                        alt: ""
                    }),
                    /*#__PURE__*/ _jsxs("div", {
                        className: classNames(styles.intbox, state.isfirst ? styles.op : styles.op2),
                        children: [
                            /*#__PURE__*/ _jsxs("div", {
                                className: classNames(styles.qhbox, "flex-center"),
                                children: [
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classNames(styles.qhboxl, "flex-center"),
                                        children: /*#__PURE__*/ _jsx("div", {
                                            className: "font-13 font-white Montserrat-Bold text-center cursor",
                                            style: {
                                                width: "100%"
                                            },
                                            onClick: function() {
                                                setState({
                                                    show: 2
                                                });
                                            },
                                            children: "EMAIL"
                                        })
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classNames(styles.qhboxlq, "flex-center flex-j-around", state.show == 2 ? styles.an1 : state.show == 1 ? styles.an2 : ""),
                                        children: /*#__PURE__*/ _jsxs("div", {
                                            className: classNames("flex-center", styles.qhboxlinfo),
                                            children: [
                                                /*#__PURE__*/ _jsx("img", {
                                                    style: {
                                                        width: "24px",
                                                        height: "24px",
                                                        marginLeft: "3px"
                                                    },
                                                    src: require("../../assets/public/backa.png"),
                                                    onClick: backbtn
                                                }),
                                                /*#__PURE__*/ _jsx("input", {
                                                    className: classNames(styles.intzi, "ml-5 Montserrat-SemiBold mr-5"),
                                                    "placeholder-class": styles.inttszi,
                                                    type: "text",
                                                    value: state.email,
                                                    onChange: function(e) {
                                                        setState({
                                                            email: e.target.value
                                                        });
                                                    },
                                                    placeholder: "EMAIL"
                                                })
                                            ]
                                        })
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classNames(styles.qhboxr, "flex-center flex-j-end"),
                                        children: /*#__PURE__*/ _jsx("div", {
                                            className: "font-13  font-white Montserrat-Bold text-center cursor",
                                            style: {
                                                width: "100%"
                                            },
                                            onClick: function() {
                                                setState({
                                                    show: 3
                                                });
                                            },
                                            children: "PHONE"
                                        })
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classNames(styles.qhboxrq, "flex-center flex-j-around", state.show == 3 ? styles.an1 : state.show == 1 ? styles.an2 : ""),
                                        children: /*#__PURE__*/ _jsxs("div", {
                                            className: classNames("flex-center", styles.qhboxrinfo, state.show == 3 ? styles.qhboxrinfox : ""),
                                            children: [
                                                /*#__PURE__*/ _jsxs("div", {
                                                    className: classNames(styles.quhao, "flex-center"),
                                                    onClick: function() {
                                                        setState({
                                                            showqh: !state.showqh
                                                        });
                                                    },
                                                    children: [
                                                        /*#__PURE__*/ _jsx("div", {
                                                            className: classNames(styles.quhaoz, "mr-5 font-12 Montserrat-SemiBold"),
                                                            children: state.areaCoed
                                                        }),
                                                        /*#__PURE__*/ _jsx("img", {
                                                            style: {
                                                                width: "8px",
                                                                height: "8px",
                                                                transform: "rotate(180deg)"
                                                            },
                                                            src: require("../../assets/public/jt.png")
                                                        })
                                                    ]
                                                }),
                                                /*#__PURE__*/ _jsx("input", {
                                                    className: classNames(styles.intzi, "ml-5 Montserrat-SemiBold", styles.phoneinput),
                                                    "placeholder-class": styles.inttszi,
                                                    type: "number",
                                                    value: state.phone,
                                                    onChange: function(e) {
                                                        setState({
                                                            phone: e.target.value
                                                        });
                                                    },
                                                    placeholder: "PHONE"
                                                }),
                                                /*#__PURE__*/ _jsx("img", {
                                                    style: {
                                                        width: "24px",
                                                        height: "24px",
                                                        marginRight: "3px"
                                                    },
                                                    src: require("../../assets/public/backa.png"),
                                                    onClick: backbtn
                                                })
                                            ]
                                        })
                                    }),
                                    state.showqh && /*#__PURE__*/ _jsx("div", {
                                        className: styles.mc,
                                        onClick: function() {
                                            setState({
                                                showqh: false
                                            });
                                        }
                                    }),
                                    state.load && /*#__PURE__*/ _jsx("div", {
                                        className: styles.sendcoin,
                                        style: {
                                            height: state.showqh ? "126px" : "0"
                                        },
                                        "v-if": "load",
                                        children: /*#__PURE__*/ _jsx("div", {
                                            className: styles.sendcoink,
                                            children: /*#__PURE__*/ _jsx("div", {
                                                className: styles.huadong,
                                                style: {
                                                    width: "80px",
                                                    height: "108px"
                                                },
                                                children: countryList.countryList.map(function(item, index) {
                                                    return /*#__PURE__*/ _jsxs("div", {
                                                        className: classNames("flex-center", styles.sendcoinlist),
                                                        "v-for": "(item, index) in countryList",
                                                        onClick: function() {
                                                            setState({
                                                                showqh: false,
                                                                areaCoed: item.area
                                                            });
                                                        },
                                                        children: [
                                                            /*#__PURE__*/ _jsx("img", {
                                                                style: {
                                                                    width: "26px",
                                                                    height: "20px"
                                                                },
                                                                src: require("../../assets/country/".concat(item.img))
                                                            }),
                                                            /*#__PURE__*/ _jsx("div", {
                                                                className: classNames("font-zi", "ml-5", styles.font - 10, "Montserrat-SemiBold"),
                                                                children: item.area
                                                            })
                                                        ]
                                                    }, index);
                                                })
                                            })
                                        })
                                    })
                                ]
                            }),
                            /*#__PURE__*/ _jsx("div", {
                                className: classNames("flex-center", styles.intk, "flex-j-around"),
                                style: {
                                    marginTop: "8px",
                                    zIndex: 1
                                },
                                children: /*#__PURE__*/ _jsx("div", {
                                    className: classNames(styles.intp, "flex-center"),
                                    children: /*#__PURE__*/ _jsx("input", {
                                        className: classNames(styles.intzi, "Montserrat-SemiBold mr-5"),
                                        "placeholder-class": styles.inttszi,
                                        type: "password",
                                        value: state.pass,
                                        onChange: function(e) {
                                            setState({
                                                pass: e.target.value
                                            });
                                        },
                                        onBlur: checkpass,
                                        placeholder: "PASSWORD"
                                    })
                                })
                            }),
                            /*#__PURE__*/ _jsxs("div", {
                                className: styles.forget,
                                children: [
                                    state.error && /*#__PURE__*/ _jsxs("div", {
                                        className: classNames("flex-center"),
                                        style: {
                                            marginTop: "2px",
                                            marginBottom: "-7px"
                                        },
                                        "v-if": "error",
                                        children: [
                                            /*#__PURE__*/ _jsx("img", {
                                                style: {
                                                    width: "10px",
                                                    height: "10px"
                                                },
                                                src: require("../../assets/public/error.png")
                                            }),
                                            /*#__PURE__*/ _jsx("div", {
                                                className: classNames("font-10 font-red  Montserrat-Medium", styles.errortxtclass),
                                                style: {
                                                    marginLeft: "-5px"
                                                },
                                                children: state.errortxt
                                            })
                                        ]
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classNames(styles["font-10"], "font-10 font-zi text-right Montserrat-Medium"),
                                        style: {
                                            marginTop: "4px",
                                            cursor: "pointer"
                                        },
                                        onClick: goforgetpass,
                                        children: "FORGET PASSWORD?"
                                    })
                                ]
                            }),
                            /*#__PURE__*/ _jsxs("div", {
                                className: styles.btnq,
                                onClick: go_login,
                                children: [
                                    /*#__PURE__*/ _jsx("img", {
                                        className: styles.btnqbg,
                                        src: require("../../assets/public/Maskgroup.png")
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classNames(styles.btnqz, "font-12", "Montserrat-SemiBold"),
                                        style: {
                                            lineHeight: "12px"
                                        },
                                        children: "LET'S"
                                    }),
                                    /*#__PURE__*/ _jsx("div", {
                                        className: classNames(styles.btnqz, "font-17", "Montserrat-Bold"),
                                        style: {
                                            lineHeight: "17px"
                                        },
                                        children: "GO!"
                                    })
                                ]
                            })
                        ]
                    })
                ]
            }),
            /*#__PURE__*/ _jsxs("div", {
                className: classNames(styles.btnbox, state.isfirst ? styles.op : styles.op2),
                onClick: goregister,
                children: [
                    /*#__PURE__*/ _jsx("div", {
                        className: "font-zi text-center font-12  Montserrat-SemiBold ",
                        children: "NO ACCOUNT YET?"
                    }),
                    /*#__PURE__*/ _jsx("div", {
                        className: classNames(styles.btnr, "flex-center flex-j-around font-zi mt-5 Montserrat-Medium font-line"),
                        children: "REGISTER FOR FREE"
                    })
                ]
            })
        ]
    });
}
export default Login;

 //# sourceMappingURL=index.js.map